package com.itheima.homework.Four;

import com.itheima.homework.Three.Computer;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/*
*
* 需求 : 往HashSet集合中添加，上题中的5个电脑对象，要求品牌、价格、颜色相同，就认为是同一个对象，
* 同一个对象指允许存在一个。
* */
public class Demo {
    public static void main(String[] args) {
        Computer c1 = new Computer("z",1000,"y");
        Computer c2 = new Computer("z",1000,"y");
        Computer c3 = new Computer("s",4000,"t");
        Computer c4 = new Computer("x",2500,"d");
        Computer c5 = new Computer("d",3600,"q");

        Comparator<Computer> comparator = (o1, o2) -> {
           if(o1.getBond()== o2.getBond()||o1.getPrice()== o2.getPrice()||o1.getColor()==o2.getColor()){
               return 0;
           }

           return 1;


        };

        Set<Computer> set = new TreeSet<Computer>(comparator);

        set.add(c1);
        set.add(c2);
        set.add(c3);
        set.add(c4);
        set.add(c5);

        System.out.println(set);

    }
}
